package com.tensquare.friend.dao;

import com.tensquare.friend.pojo.Friend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @ClassName FriendDao
 * @Description 交友数据访问层
 * @Author zhangshuai
 * @Date 2019/1/26 21:13
 * @Version 1.0
 **/
public interface FriendDao extends JpaRepository<Friend, String> {


    /**
     * 删除喜欢
     * @param userid
     * @param friendid
     */
    @Modifying
    @Query(value = "DELETE FROM tb_friend  WHERE userid = ?1 AND friendid = ?2",nativeQuery = true)
    public void deleteFriend(String userid,String friendid);


    /**
     * 根据用户id与被关注用户ID查询记录个数
     *
     * @param userid
     * @param friendid
     * @return
     */
    @Query(value = "SELECT count(*) FROM tb_friend f WHERE f.userid = ? AND f.friendid =?", nativeQuery = true)
    public int selectCount(String userid, String friendid);


    /**
     * 更新为相互喜欢
     *
     * @param userid
     * @param friendid
     * @param islike
     */
    @Modifying
    @Query(value = "update tb_friend f set f.islike=?3 where f.userid = ?1 and f.friendid = ?2", nativeQuery = true)
    public void updateLike(String userid, String friendid, String islike);

}
